package com.zb_study.api_;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class API_ {
    public static void main(String[] args) throws UnknownHostException {

        InetAddress localHost = InetAddress.getLocalHost();
        System.out.println(localHost); //LAPTOP-D565O2TI/192.168.137.1


        InetAddress host1 = InetAddress.getByName("LAPTOP-D565O2TI");
        System.out.println("host1= " +host1);

        InetAddress host2 = InetAddress.getByName("www.baidu.com");
        System.out.println("host2= "+host2);

        String hostAddress = host2.getHostAddress();
        System.out.println("host 对应的ip= "+hostAddress);

        String hostName = host2.getHostName();
        System.out.println("host2对应的域名= "+hostName);
    }
}
